using System.Linq.Expressions;



public class TodoNameRemarkStatusFiltereSpecification : Specification<EleTodo>
{
    private string? _name;
    private string? _remark;
    private TodoStatus? _status;

    public TodoNameRemarkStatusFiltereSpecification(string? name, string? remark, TodoStatus? status)
    {
        _name = name;
        _remark = remark;
        _status = status;
    }

    public override Expression<Func<EleTodo, bool>> ToExpression()
    {
        Expression<Func<EleTodo, bool>> filter = PredicateBuilder.True<EleTodo>();

        if (!string.IsNullOrEmpty(_name))
        {
            filter = filter.Compose(x => x.Name.Contains(_name), Expression.AndAlso);
        }

        if (!string.IsNullOrEmpty(_name) && !string.IsNullOrEmpty(_remark))
        {
            filter = filter.Compose(x => x.Name.Contains(_name) && (x.Remark == null ? false : x.Remark.Contains(_remark)), Expression.AndAlso);
        }

        if (!string.IsNullOrEmpty(_name) && !string.IsNullOrEmpty(_remark) && _status != null)
        {
            filter = filter.Compose(
                x => x.Name.Contains(_name) && (x.Remark == null ? false : x.Remark.Contains(_remark)) && x.Status == _status,
                Expression.AndAlso
            );
        }

        return filter;
    }
}